import { DomWarBeaContentPannel } from "./DomWarBeaContentPannel";
import { FlowerBg } from "../../common/FlowerBg";
import { ObjCreate } from "../../common/ObjCreate";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { ResFileConst } from "../../../resource/ResFileConst";
import { Cache } from "../../../cache/Cache";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { MsgManager } from "../../../manager/MsgManager";
import { Language } from "../../../../../extend/language/Language";
import { DomWarBeaOtherPartBase } from "./otherPart/DomWarBeaOtherPartBase";
import { UnionInfoPart } from "./otherPart/UnionInfoPart";
import { SiegeInfoPart } from "./otherPart/SiegeInfoPart";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../../resource/ImagesConst";
import { SecTimer } from "../../../../../com/gengine/core/frame/SecTimer";
import { TimerType } from "../../../../../com/gengine/core/frame/TimerType";
import { ClockManager } from "../../../manager/ClockManager";
import { RemainTimeTool } from "../../award/RemainTimeTool";
import { SDominionBattlePreviewInfo } from "../../../../../Message/Public/SDominionBattlePreviewInfo";
import { SDominionBattleSituationInfos } from "../../../../../Message/Public/SDominionBattleSituationInfos";
import { SiegeUnionPartBase } from "./otherPart/SiegeUnionPartBase";
import { GTextFiled } from "../../../../../com/mui/controls/GTextFiled";
import { GLoadedButton } from "../../../../../com/mui/controls/GLoadedButton";
type int = number;
//class SiegeUnionPannel
    
    export  class SiegeUnionPannel extends DomWarBeaContentPannel
    {
        constructor(arg1: string="", arg2: Boolean=true, arg3: string="", arg4: number=590, arg5: number=480)
        {
            super(arg1, arg2, arg3, arg4, arg5);
            return;
        }

        protected /* override */ configUI(): void
        {
            this._introBmp = new Object /* flash.display.Bitmap */();
            super.configUI();
            this._flowerBg = new FlowerBg(792, 120);
            this._flowerBg.x = 3;
            this._flowerBg.y = 3;
            this.addChild(this._flowerBg);
            this.addChild(this._introBmp);
            this._introBmp.x = 186;
            this._introBmp.y = 27;
            this._timeTxt = ObjCreate.createGTextField("00: 00: 00", 385, 92, 100, 20, this, GlobalStyle.textFormat5);
            this._bgImage.x = 3;
            this._bgImage.y = 126;
            this._partMap = new Map<any, any> /* flash.utils.Dictionary */();
            this._siegeInfoBtn = ObjCreate.createGLoadedButton(ResFileConst.DomWarSiegeInfoBtn, 612, 20, 158, 91, this);
            this._siegeInfoBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onClick);
            this._unionInfoBtn = ObjCreate.createGLoadedButton(ResFileConst.DomWarUnionInfoBtn, 21, 20, 158, 91, this);
            this._unionInfoBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onClick);
            this.onClick();
            return;
        }

        protected onClick(arg1: Object /* flash.events.MouseEvent */=null): void
        {
            var loc1=0;
            if (arg1) 
            {
                var loc2=arg1.currentTarget;
                switch (loc2) 
                {
                    case this._unionInfoBtn:
                    {
                        loc1 = 0;
                        break;
                    }
                    case this._siegeInfoBtn:
                    {
                        loc1 = 1;
                        break;
                    }
                }
            }
            this.handerPart(loc1);
            return;
        }

        /* internal  */handerPart(arg1: int): void
        {
            if (arg1 != 0) 
            {
                if (arg1 == 1) 
                {
                    if (Cache.instance.dominionBea.canOpenSiege()) 
                    {
                        this._timeTxt.visible = false;
                        Dispatcher.dispatchEvent(new DataEvent(EventName.GetDomWarBeaPannelInfo, {"index": 3}));
                    }
                    else 
                    {
                        MsgManager.showRollTipsMsg(Language.getString(90670));
                        return;
                    }
                }
            }
            else 
            {
                this._timeTxt.visible = true;
                Dispatcher.dispatchEvent(new DataEvent(EventName.GetDomWarBeaPannelInfo, {"index": 2}));
            }
            if (this._curIndex != arg1) 
            {
                this._curIndex = arg1;
                if (this._curPart) 
                {
                    this._curPart.hide();
                }
                this._curPart = this.getPart(arg1);
                this._curPart.show(this);
            }
            this.setIntroBmp();
            return;
        }

        /* internal  */getPart(arg1: int): DomWarBeaOtherPartBase
        {
            var loc1=null;
            if (!this._partMap[arg1]) 
            {
                var loc2=arg1;
                switch (loc2) 
                {
                    case 0:
                    {
                        loc1 = new UnionInfoPart("", false);
                        loc1.x = 3;
                        loc1.y = 136;
                        break;
                    }
                    case 1:
                    {
                        loc1 = new SiegeInfoPart("", false);
                        loc1.x = 4;
                        loc1.y = 124;
                        break;
                    }
                }
                this._partMap[arg1] = loc1;
            }
            return this._partMap[arg1] as DomWarBeaOtherPartBase;
        }

        protected /* override */ onImageLoaded(): void
        {
            super.onImageLoaded();
            this.setIntroBmp();
            return;
        }

        /* internal  */setIntroBmp(): void
        {
            if (this._isLoaded) 
            {
                if (this._curIndex != 0) 
                {
                    if (this._curIndex == 1) 
                    {
                        this._introBmp.bitmapData = GlobalClass.getBitmapData(ImagesConst.DWBTxtImage_siegeIntro);
                    }
                }
                else 
                {
                    this._introBmp.bitmapData = GlobalClass.getBitmapData(ImagesConst.DWBTxtImage_unionIntro);
                }
            }
            return;
        }

        /* internal  */startTimer(): void
        {
            if (!this._secTimer) 
            {
                this._secTimer = new SecTimer(1);
                this._secTimer.addListener(TimerType.ENTERFRAME, this.onTimerRun);
            }
            this._secTimer.reset();
            this._secTimer.start();
            return;
        }

        /* internal  */onTimerRun(arg1: SecTimer): void
        {
            var loc1=NaN;
            if (Cache.instance.dominionBea.isInUnion()) 
            {
                loc1 = Cache.instance.dominionBea.dateState.endDate.time - ClockManager.instance.nowDate.time;
                loc1 = loc1 / 1000;
                this._timeTxt.text = RemainTimeTool.getRemainTimeBySeconds(loc1);
            }
            else 
            {
                this.stopTimer();
            }
            return;
        }

        /* internal  */stopTimer(): void
        {
            if (this._secTimer) 
            {
                this._secTimer.stop();
            }
            return;
        }

        public /* override */ hide(): void
        {
            super.hide();
            this.stopTimer();
            return;
        }

        public /* override */ show(arg1: Object /* flash.display.DisplayObjectContainer */): void
        {
            super.show(arg1);
            this.startTimer();
            if (Cache.instance.dominionBea.canOpenSiege()) 
            {
                this.handerPart(1);
            }
            return;
        }

        public /* override */ update(arg1: Object): void
        {
            var loc1=null;
            var loc3=null;
            var loc4=null;
            var loc5=null;
            var loc2=-1;
            if (typeof arg1 === "sdominionbattlepreviewinfo") 
            {
                loc1 = (loc3 = arg1 as SDominionBattlePreviewInfo).battlePreviews;
                loc2 = 0;
            }
            else if (typeof arg1 === "sdominionbattlesituationinfos") 
            {
                loc1 = (loc4 = arg1 as SDominionBattleSituationInfos).situationInfos;
                loc2 = 1;
            }
            if (loc1 && !(loc2 == -1)) 
            {
                if (loc5 = this.getPart(loc2)) 
                {
                    loc5.update(loc1);
                }
            }
            return;
        }

        public receiveInvite(): void
        {
            var loc1=this.getPart(0) as SiegeUnionPartBase;
            if (loc1) 
            {
                loc1.flashUnionBtn();
            }
            return;
        }

        public /* override */ destroy(): void
        {
            super.destroy();
            this._siegeInfoBtn.removeEventListener(flash.events.MouseEvent.CLICK, this.onClick);
            this._unionInfoBtn.removeEventListener(flash.events.MouseEvent.CLICK, this.onClick);
            return;
        }

        /* internal */ /* var */_introBmp: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_flowerBg: FlowerBg;

        /* internal */ /* var */_timeTxt: GTextFiled;

        /* internal */ /* var */_siegeInfoBtn: GLoadedButton;

        /* internal */ /* var */_unionInfoBtn: GLoadedButton;

        /* internal */ /* var */_partMap: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ /* var */_curPart: DomWarBeaOtherPartBase;

        /* internal */ /* var */_curIndex: int=-1;

        /* internal */ /* var */_secTimer: SecTimer;
    }
